package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.saas.domain.entity.ext.CreditLimitEntityExt;

import java.util.Collection;
import java.util.List;

/**
 * 信用额度
 * @author xingxing.xiao
 * @date 2020/12/22 20:26
 */
public interface CreditLimitService {

    /**
     * 保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     */
    void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 设置保存固定额度所需参数
     * @param saasFormSaveDTO
     * @return
     * @throws XbbException
     */
    FormDataAddDTO setFixedFormDataAddDTO(SaasFormSaveDTO saasFormSaveDTO, Double fixedLimit) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities 业务实体集合
     * @param totalCount 总数
     * @return ListAppVO
     * @throws XbbException
     */
    ListAppVO formatCreditAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * 根据 customerId 查询 creditLimitEntity
     * @param customerId
     * @param corpid
     * @return
     */
    CreditLimitEntityExt getCreditByCustomerId(Long customerId, String corpid) throws XbbException;

    /**
     * 通过客户id集合查询creditLimitEntityList
     * @param customerIdIn
     * @param corpid
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.CreditLimitEntityExt>
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    List<CreditLimitEntityExt> getCreditByCustomerIdIn(Collection<Long> customerIdIn, String corpid) throws XbbException;

    /**
     * 计算信用额度相关内容 - 临时额度、已用额度、可用额度
     * @param
     * @return
     */
    void calculateCreditLimit(String corpid, Integer distributorMark, List<PaasFormDataEntityExt> paasFormDataESList) throws XbbException;

    /**
     * 计算信用额度相关内容 - 临时额度、已用额度、可用额度
     * @param
     * @return
     */
    void calculateCreditLimitSingle(String corpid, Integer distributorMark, JSONObject data) throws XbbException;

    /**
     * 计算有效期内临时额度之和
     * @param
     * @return
     */
    void calculateCreditTemporaryLimit(String corpid, Integer distributorMark, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException;

    /**
     *  @param corpid
     * @param distributorMark
     * @param creditStatus 信用账户状态 CreditLimitStatusEnum.java
     */
    List<CreditLimitEntityExt> getCreditDistributors(String corpid, Integer distributorMark, String creditStatus);

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValueBefore(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 名称一致性同步
     * @param corpid
     * @param customerId
     * @param customerName
     * @throws XbbException
     */
    void dataConsistencyUpdateCustomer(String corpid, Long customerId, String customerName) throws XbbException;

}
